package com.tuanzi.loan.business.repository.receipt.statistics.impl;

import com.tuanzi.loan.business.repository.receipt.statistics.ReceiptLoanProductClickUvRepository;
import com.tuanzi.loan.business.repository.receipt.statistics.custom.ReceiptLoanProductClickUvCustom;
import com.tuanzi.loan.core.repository.JOOQBaseRepositoryPlus;
import org.jooq.impl.TableImpl;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;

import static com.tuanzi.loan.generated.jooq.loan.tables.LoanProductClickUv.LOAN_PRODUCT_CLICK_UV;

/**
 * @Auther: hequnayu
 * @Date: 2019/6/5 17:35
 * @Description:
 */
@Repository
public class ReceiptLoanProductClickUvRepositoryImpl extends JOOQBaseRepositoryPlus implements ReceiptLoanProductClickUvCustom {
    @Override
    public Long countTodayProductClickUvCustom(Long prdid, LocalDate date) {
        String sql = "SELECT COUNT(DISTINCT phoneid) FROM `loan_product_click_uv` WHERE ACTIVITY_ID='"+prdid.toString()+"' AND createdate = '"+date.toString()+"';";
        return dslContext.fetchOne(sql).into(Long.class);
    }

    @Override
    protected TableImpl getTable() {
        return LOAN_PRODUCT_CLICK_UV;
    }

}
